package com.easondongh.common.controller;

import com.easondongh.common.Utils.UploadService;
import com.easondongh.common.enums.ResponseEnum;
import com.easondongh.common.response.ResponseObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author EasonDongH
 * @date 2020/5/23 22:46
 */
@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * 图片上传
     * @param file
     * @return
     */
    @RequestMapping(value="/image")
    public ResponseObj<String> uploadImage(@RequestBody MultipartFile file) {
        String url = uploadService.uploadImage(file);
        return new ResponseObj<>( ResponseEnum.UPLOAD_SUCCESS, url);
    }
}
